package cn.cjxy.web.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 *
 * session作用域存值
 * session也是一个域对象，也有域对象的几个方法，如下：
 *      HttpSession的方法	                        作用
 *      Object getAttribute("名字")	                从会话域中得到一个值
 *      void setAttribute("名字",Object数据)	        向会话域中添加一对键和值
 *      void removeAttribute("名字")	                    从会话域中删除键和值
 * @author huangjie
 * @date 2025/9/27
 */
@WebServlet("/set")
public class SessionDemo2 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       //得到session对象
        HttpSession session = req.getSession();
        //存入
        session.setAttribute("username","lisi");
        resp.getWriter().print("OK");
    }
}
